
export const dateShortcutKeyJS = {
  data() {
    return {
      // 时间选择限制
      pickerMinDate: '',
      datePickerOptions: {
        disabledDate: time => {
          return time.getTime() > Date.now();
        }
      },
      pickerOptions: {
        shortcuts: [
          {
            text: '最近7天',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 6);
              picker.$emit('pick', [date, new Date()]);
            }
          },
          {
            text: '最近15天',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 14);
              picker.$emit('pick', [date, new Date()]);
            }
          },
          {
            text: '最近30天',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 29);
              picker.$emit('pick', [date, new Date()]);
            }
          }
        ],
        onPick: ({ maxDate, minDate }) => {
          this.pickerMinDate = minDate.getTime();
          if (maxDate) {
            this.pickerMinDate = '';
          }
        },
        disabledDate: time => {
          if (this.pickerMinDate !== '') {
            const day30 = (30 - 1) * 24 * 3600 * 1000;
            let maxTime = this.pickerMinDate + day30;
            if (maxTime > new Date()) {
              maxTime = new Date();
            }
            return time.getTime() > maxTime;
          }
          return time.getTime() > Date.now();
        }
      }
    };
  }
};
